from web_server_function.CourseServer import course_server
from web_server_function.UserServer import user_server
from web_server_function.ServerUtils import server_utils
from utils.ReadUtil import read_util
import argparse


# orderno = 'T1715440260283'
# userphone = '13800000006'
#
# # 超管登录
# server_utils.login_background(read_util.read_data()['后台账号密码']['超管账号'],
#                               read_util.read_data()['后台账号密码']['超管密码'])
#
# # 查询课程
# course_list_id = course_server.get_course_id(order_no=orderno)
# print(f'课程id为{course_list_id}')
#
# # 查询用户id
# user_id = user_server.get_user_info_id(mobilePhone=userphone)
# print(f'用户id为{user_id}')
#
# # 设置课程金额
# print(course_server.setting_course_money(course_list=course_list_id, order_no=orderno))
#
# # 添加退课申请
# print(course_server.add_course_withdrawal_Request(orders_id=course_list_id, user_info_id=user_id, orders_no=orderno))
#
# # 查询课程订单rsno
# rsno = course_server.query_courseupdate_rsno(orderno=orderno)
# print(f'课程订单rsno号为{rsno}')
#
# # 部门负责人审核退课
# print(course_server.refund_review_by_manager(rsno))
#
# # 超管登录
# server_utils.login_background(read_util.read_data()['后台账号密码']['超管账号'],
#                               read_util.read_data()['后台账号密码']['超管密码'])
#
# # 财务审核退款
# print(course_server.finance_confirm_receipt_refund(orderno=orderno, courselistid=course_list_id))

def auditRefund(orderno, userphone):
    # 超管登录
    server_utils.login_background(read_util.read_data()['后台账号密码']['超管账号'],
                                  read_util.read_data()['后台账号密码']['超管密码'])
    # 查询订单id
    orderlist = course_server.get_course_order_list(orderno)
    course_list_id = server_utils.get_button_value_from_response(orderlist, '学习计划', 'getCourseList')
    print(f"课程订单id为{course_list_id}")
    # 查询用户id
    user_id = user_server.get_user_info_id(mobilePhone=userphone)
    print(f'用户id为{user_id}')
    # 设置课程金额
    print(course_server.setting_course_money(course_list=course_list_id, order_no=orderno))
    # 添加退课申请
    print(course_server.add_course_withdrawal_Request(orders_id=course_list_id, user_info_id=user_id,
                                                      orders_no=orderno))
    # 查询课程订单rsno
    rsno = course_server.query_courseupdate_rsno(orderno=orderno)
    print(f'课程订单rsno号为{rsno}')
    # 部门负责人审核退课
    print(course_server.refund_review_by_manager(rsno))
    # 超管登录
    server_utils.login_background(read_util.read_data()['后台账号密码']['超管账号'],
                                  read_util.read_data()['后台账号密码']['超管密码'])
    # 超管审核退款
    print(course_server.finance_confirm_receipt_refund(orderno=orderno, courselistid=course_list_id))


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='执行审核退课申请操作')
    parser.add_argument('orderno', type=str, help='订单编号')
    parser.add_argument('userphone', type=str, help='手机号码')
    args = parser.parse_args()

    auditRefund(args.orderno, args.userphone)
